package org.diffshop.common.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @Author:tjf
 * @Description:
 */
@EnableTransactionManagement
@MapperScan(basePackages = {"org.diffshop.product.dao", "org.diffshop.coupon.dao", "org.diffshop.ware.dao"})
@Configuration
public class MybatisConfig {
    /**
     * 添加分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        // 当请求页下标大于页总数数，true：返回第一页数据 false：返回请求页下标+1
        paginationInterceptor.setOverflow(true);

        interceptor.addInnerInterceptor(paginationInterceptor); // 如果配置多个插件, 切记分页最后添加
        return interceptor;
    }
}
